package com.mail.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.PmsProductAttributeCategoryApi;
import com.mail.model.db.PmsProductAttributeCategory;
import com.mail.model.vo.PageResult;
import com.mail.model.vo.ProductAttributeVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PmsProductAttributeCategoryService {

    @DubboReference
    private PmsProductAttributeCategoryApi productAttributeCategoryApi;

    // 添加商品属性分类
    public void addProductAttributeCategory(String name) {
        productAttributeCategoryApi.addProductAttributeCategory(name);
    }

    // 删除单个商品属性分类
    public void deleteById(Long attributeId) {
        productAttributeCategoryApi.deleteById(attributeId);
    }

    // 分页获取所有商品属性分类
    public PageResult queryProductAttributeList(Integer pageNum, Integer pageSize) {
        PageResult pageResult = new PageResult();
        Page<PmsProductAttributeCategory> page = productAttributeCategoryApi.queryProductAttributeList(pageNum,pageSize);
        pageResult.setList(page.getRecords());
        pageResult.setPageNum(page.getCurrent());
        pageResult.setPageSize(page.getSize());
        pageResult.setTotalPage(page.getPages());
        pageResult.setTotal(page.getTotal());
        return pageResult;
    }

    // 获取所有商品属性分类及其下属性
    public List<ProductAttributeVo> queryListWithAttr() {
        List<ProductAttributeVo> productAttributeVoList = productAttributeCategoryApi.queryListWithAttr();
        return productAttributeVoList;
    }

    // 修改商品属性分类
    public void updateAttributeCategory(Long id, String name) {
        productAttributeCategoryApi.updateAttributeCategory(id,name);
    }

    // 获取单个商品属性分类信息
    public PmsProductAttributeCategory queryAttributeCategoryById(Long id) {
        PmsProductAttributeCategory productAttributeCategory = productAttributeCategoryApi.queryAttributeCategoryById(id);
        return productAttributeCategory;
    }
}
